import 'package:flutter/material.dart';
import 'package:flutter_scaffold/flutter_scaffold.dart';

class RoutePageDemo extends StatefulWidget {
  const RoutePageDemo({super.key});

  @override
  State<RoutePageDemo> createState() => _RoutePageDemoState();
}

class _RoutePageDemoState extends State<RoutePageDemo> {
  late Map args;

  @override
  void initState() {
    super.initState();
     //方法一：get方式
    args = Get.routing.args as Map<String, dynamic>;
  }

  @override
  Widget build(BuildContext context) {
    //方法二：官方方式
    //args = ModalRoute.of(context)?.settings.arguments as Map<String, dynamic>;
    return BindViewModel<BaseDefaultViewModel>(
      init: BaseDefaultViewModel(),
      builder: (context) {
        return Scaffold(
          appBar: AppBar(title: Text("路由demo")),
          body: Text("接受参数:${args["title"]}"),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.close),
            onPressed: (){
              Get.back(result: "我关闭了,给你数据了");
            },
          ),
        );
      },
    );
  }
}
